﻿using System;
using TiaoTiaoCode.Common.Extensions;

namespace TiaoTiaoCode.AutoUpdate.Common.Dtos
{
    /// <summary>
    /// 主程序创建Dto
    /// </summary>
    public class MainProgramCreateDto
    {
        /// <summary>
        /// 程序名
        /// </summary>
        public string? ProgramName { get; set; } = default!;

        /// <summary>
        /// 服务器路径
        /// </summary>
        public string? FilePath { get; set; } = default!;
    }

    /// <summary>
    /// 主程序更新Dto
    /// </summary>
    public class MainProgramUpdateDto : MainProgramCreateDto
    {
        /// <summary>
        /// Id
        /// </summary>
        public string Id { get; set; } = default!;

        /// <summary>
        /// 主版本
        /// </summary>
        public int Major { get; set; }

        /// <summary>
        /// 子版本
        /// </summary>
        public int Version { get; set; }

        /// <summary>
        /// 修订版本
        /// </summary>
        public int MinorNumber { get; set; }

        /// <summary>
        /// 编译版本
        /// </summary>
        public int BuildNumber { get; set; }

        /// <summary>
        /// 自定义版本
        /// </summary>
        public string? CustomVersion { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreateDate { get; set; }

        /// <summary>
        /// 是否发布
        /// </summary>
        public bool IsPublish { get; set; }

        /// <summary>
        /// 版本发布说明
        /// </summary>
        public string? Comment { get; set; } = default!;
    }

    /// <summary>
    /// 主程序信息显示
    /// </summary>
    public class MainProgramView : MainProgramUpdateDto
    {
        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime? UpdateDate { get; set; }

        /// <summary>
        /// 是否删除标记
        /// </summary>
        public bool IsDelete { get; set; }

        /// <summary>
        /// 拼好的版本号
        /// </summary>
        public string VersionStr => $"{Major}.{Version}.{MinorNumber}.{BuildNumber}{(CustomVersion.TiaoTiaoIsNullOrEmpty() ? string.Empty : $".{CustomVersion}")}";
    }
}
